$(function () {
    //删除选定行
    $('.cut').click(function () {
        if ($('.sonCheck:checked').length > 0) {
            if (confirm("确认要删除吗?")) {
                $('.sonCheck:checked').parent().parent().remove()
            }
        } else {
            alert('未选中商品！')
        }
    })

    //删除单行
    $('.remove').click(function () {
        if (confirm("确认要删除吗?")) {
            $(this).parent().parent().remove();
        }
    })

    //全选
    $(".all").click(function () {
        $(".sonCheck").prop("checked", this.checked);
    });

    //跳转到添加界面跳转
    $(".add").click(function () {
        window.location.href = "bookManage-add.html"
    });

    //跳转到修改图书界面
    $(".update").click(function () {
        window.location.href = "bookManage-update.html"
    });

    //返回到图书管理界面
    $(".return").click(function () {
        window.location.href = "bookManage.html"
    });
})
function selectFile() {
    $(".choose").trigger("click");
}
function initData() {
    // var buyProducts = JSON.parse(sessionStorage.getItem('buyProducts'))
    var strHTML = `<tr>
                        <td><input type="checkbox" class="sonCheck">选择</input></td>
                        <td class="photo">
                            <div>
                                <img src="images/kdy3.jpg" alt="图书">
                            </div>
                        </td>
                        <td class="detail">
                            <span>书名:</span>
                            <span>作者:</span><br>
                            <span>库存数量:</span>
                            <span>售价:</span><br>
                            <span>出版社:</span>
                            <span>书码:</span><br>
                            <span>分类:</span>
                        </td>
                        <td><button class="remove">删除</button></td>
                </tr>`
    for (var i = 0; i < books.length; i++) {
        strHTML += `<tr>
                        <td><input type="checkbox" class="sonCheck">选择</input></td>
                        <td class="photo">
                            <div>
                                <img src="${books[i].bName}" alt="图书">
                            </div>
                        </td>
                        <td class="detail">
                            <span>${books[i].bName}</span>
                            <span>${books[i].bName}</span><br>
                            <span>${books[i].bName}</span>
                            <span>${books[i].bName}</span><br>
                            <span>${books[i].bName}</span>
                            <span>${books[i].bName}</span><br>
                            <span>${books[i].bName}</span>
                        </td>
        <td><button class="remove">删除</button></td>
</tr>`
    }
    document.querySelector('#myTableProduct').innerHTML = strHTML
}